function getPops (text) {
  const sArr = ['"', "'"]
  const b1Arr = ['{', '[', '(', '`']
  const b2Arr = ['}', ']', ')', '`']

  let start = 0
  let end = 0
  text.replace(/(['"]*)props\1 *: *[\[{]/, function (m, p1, index) {
    let n = index + m.length - 1
    let left = 0

    let lock = true
    while (lock && n < text.length) {
      if (sArr.indexOf(text[n]) > -1) {
        const cur = text[n]
        while (text[n + 1] !== cur && n + 1 < text.length) {
          n++
        }
        n++
      } else if (b1Arr.indexOf(text[n]) > -1) {
        if (left === 0) {
          start = n
        }
        left++
      } else if (b2Arr.indexOf(text[n]) > -1) {
        left--
        // 结束
        if (left === 0) {
          end = n + 1
          lock = false
        }
      }
      n++
    }
  })
  const str = text.substring(start, end)
  const props = new Function('return ' + str)()
  return props
}

import SearchClass from './SearchClass';
const getMockByProps = require('./getMockByProps')
import suiMap from '../components/suiPlugin';

export const vueTextMap ={}
export const mockMap={}
export const keywordList=[]

suiMap.list.forEach(function (view,i) {
  const text =suiMap.textList[i]
  const name=suiMap.name+'-' + view
  vueTextMap[name]=text
  if (/\/\/ *keyword=(.+)/.test(text)) {
    const props = getPops(text)
    const mock=getMockByProps(props)
    text.replace(/\/\/ *keyword=(.+)/g,function (m,p1) {
      keywordList.push(name+p1.replace(/\d/g,function (d) {
        return '#'.repeat(d)+','
      }).replace(/，/g,','))
      mockMap[name]=mock
    })
  }
})

const search=new SearchClass(keywordList)
export default search